import requests
def parse_str_dict(strs):
    # n2 = 'page=1,\nlimit=1'
    str_list = strs.split('\n')
    # print(str_list)
    data = []
    for str in str_list:
        # 去掉 逗号,
        s = str.replace(',','')
        data.append(s.split('='))
    # print(dict(data))
    return dict(data)


from openpyxl import load_workbook
wb = load_workbook(filename='./api.xlsx')
ws = wb.active
for row in ws.iter_rows(min_row=1,max_row=ws.max_row,min_col=1,max_col=ws.max_column,values_only=True):
    print(row)
    id = row[0]
    method = row[1]
    url = "http://47.100.175.62:3000/api/v1"+row[2]
    header = row[3]
    qurydata = row[4]
    if method=='GET':
        if header == "无":
            headers = {}
        # 'page=1' => {"page":1}
        paramsdata = parse_str_dict(qurydata)
        r = requests.get(url=url,headers=headers,params=paramsdata)
        print(f'发送请求，编号：{id},请求方法{method},请求路径:{url},\n请求头：{headers},请求数据:{paramsdata},\n'
                  f'返回状态码:{r.status_code},返回结果:{r.json()}')

